package com.simple.datax.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.simple.base.dao.BaseDAO;
import com.simple.datax.dao.ITbResourcesDAO;
import com.simple.datax.vo.TbResourcesIdVO;
import com.simple.datax.vo.TbResourcesVO;

@Repository("tbResourcesDAO")
public class TbResourcesDAOImpl extends BaseDAO implements ITbResourcesDAO {

	@Override
	public TbResourcesVO findById(TbResourcesIdVO id) {
		return super.get(TbResourcesVO.class,id);
	}

	@Override
	public List<TbResourcesVO> findAll() {
		return super.query(TbResourcesVO.class);
	}

	@Override
	public void saveOrUpdate(TbResourcesVO tbResourcesVo) {
		super.saveOrUpdate(tbResourcesVo);
	}

	@Override
	public void delete(TbResourcesVO tbResourcesVo) {
		super.delete(tbResourcesVo);
	}

	@Override
	public List<TbResourcesVO> findByPackages(String[] _packageAry) {
		final List<TbResourcesVO> tbResourcesVOList;
		Object[] objs = new Object[_packageAry.length];
		final StringBuffer hql = new StringBuffer(200);
		hql.append("from TbResourcesVO t ");
		if (_packageAry.length > 0) {
			hql.append("where t.id.packageString = ? ");
			objs[0] = _packageAry[0];
			for (int i = 1; i < _packageAry.length; i++) {
				hql.append("or t.id.packageString = ? ");
				objs[i] = _packageAry[i];
			}
			tbResourcesVOList = super.query(hql.toString(), objs);
		} else {
			tbResourcesVOList = super.query(hql.toString());
		}
		
		return tbResourcesVOList;
	}

}
